﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="PersonExpertForgetPwd.aspx.cs" Inherits="RN.ERP.Web.Person.PersonExpertForgetPwd" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>忘记密码</title>
    <link rel="Stylesheet" type="text/css" href="../Scripts/ligerUI/skins/Aqua/css/ligerui-all.css" />
    <link rel="Stylesheet" type="text/css" href="../Styles/skins/blue/css/style.css" />
    <link rel="Stylesheet" type="text/css" href="../Styles/skins/blue/css/style_msg.css" />
    <style>
        .IE6png{behavior: url("js/iepngfix.htc");}
        #btnSend{padding: 5px 10px;background: rgb(255, 199, 56);margin-left: 10px;}
        #btnSend.disabled{background:lightgray;color:Gray;}
    </style>
</head>
<body>
    <form id="form2" runat="server">
    <div class="main_tt">
        <div class="main_tt_r_p15">
            <!--title_tt 开始-->
            <div class="title_tt">
                <div class="title_tt_l">
                    <img src="../images/tt_title_l.jpg" width="9" height="33" />
                    <img src="../images/xx_icon.jpg" width="24" height="33" />
                </div>
                <div class="title_tt_h">找回密码</div>
                <div class="title_tt_r">
                    <img src="../images/tt_title_r.jpg" width="9" height="33" />
                </div>
            </div>
            <!--title_tt 结束-->

            <!--userinfo_tt 开始-->
            <div class="userinfo_tt">
                <div id="sendVerCodePage" style="display:none;">
                    <div class="xian">
                        <div class="about_title">发送验证码</div>
                    </div>
                    <div  class="userinfo_tt_left">
                        <ul>
                            <li>
                                <label>手机号</label>
                                <span class="input_l"><img src="../images/input_l.jpg" width="10" height="31" alt="" /></span>
                                <span class="input_mm"><input id="txtPhone" type="text" class="inp" maxlength="11" /></span>
                                <input type="button" id="btnSend" value="发送" />
                                <span class="input_r"><img src="../images/input_r.jpg" width="10" height="31" alt="" /></span>
                            </li>
                            <li>
                                <label>验证码</label>
                                <span class="input_l"><img src="../images/input_l.jpg" width="10" height="31" alt="" /></span>
                                <span class="input_mm"><input id="txtVerCode" type="text" class="inp" maxlength="6" /></span>
                                <span class="input_r"><img src="../images/input_r.jpg" width="10" height="31" alt="" /></span>
                            </li>
                            <li>
                                <label>&nbsp;</label>
                                <span class="ckicon02"><a id="btnToChangePwd" style="text-decoration:none;" href="###">确认</a></span>
                            </li>
                        </ul>
                    </div>

                    <div class="clear"></div>
                    <div class="xian">
                        <div class="about_title">姓名/身份证号码变更</div>
                    </div>
                    <div  class="userinfo_tt_left">
                        <ul>
                            <li>
                                <label>&nbsp;</label>
                               <a id="btnChange" style="text-decoration:none;" href="PersonExpertChangeNaI.aspx"><span class="ckicon02">点击</span></a>
                            </li>
                        </ul>
                    </div>
                </div>
                <div id="changePwdPage" style="display:none;">
                    <div class="xian">
                        <div class="about_title">修改密码</div>
                    </div>
                    <div class="userinfo_tt_left">
                        <ul>
                            <li>
                                <label>新密码</label>
                                <span class="input_l"><img src="../images/input_l.jpg" width="10" height="31" alt="" /></span>
                                <span class="input_mm"><input id="pwd" type="password" class="inp" /></span>
                                <span class="input_r"><img src="../images/input_r.jpg" width="10" height="31" alt="" /></span>
                            </li>
                            <li>
                                <label>确认密码</label>
                                <span class="input_l"><img src="../images/input_l.jpg" width="10" height="31" alt="" /></span>
                                <span class="input_mm"><input id="pwd2" type="password" class="inp" /></span>
                                <span class="input_r"><img src="../images/input_r.jpg" width="10" height="31" alt="" /></span>
                            </li>
                            <li>
                                <label>&nbsp;</label>
                                <span class="ckicon02"><a id="btnChangePwd" style="text-decoration:none;" href="###">更改密码</a></span>
                            </li>
                        </ul>
                    </div>
                </div>
                <div class="clear"></div>
            </div>
            <!--userinfo_tt 结束-->
        </div>
    </div>
    </form>

    <script src="../Scripts/jquery-1.7.min.js" type="text/javascript"></script>
    <script src="../Scripts/ligerUI/js/ligerui.min.js" type="text/javascript"></script>
    <script title="common">
        var validitor = {
            //手机号
            phone: function (p) {
                return /^1[3-8]\d{9}$/.test(p);
            }
            , vercode: function (c) {
                return /^\d{6}$/.test(c);
            }
            , pwd: function (p) {
                var patrn = /^(?=.*[a-zA-Z])(?=.*[0-9])[a-zA-Z0-9]{6,}$/;
                return !!patrn.exec(p);
            }
        };
    </script>
    <script type="text/javascript">
        var phoneNum, verCode, isLoading;

        //初始化操作
        var hashChange = function (h) {
            if (h) location.hash = h;

            var hash = location.hash;
            
            if (hash == "#sendVerCodePage" || hash == "") {
                $("#sendVerCodePage").show();
                $("#changePwdPage").hide();
            } else if (hash == "#changePwdPage") {
                $("#sendVerCodePage").hide();
                $("#changePwdPage").show();
            }
        };
        hashChange();
        
        //点击【发送】
        $("#btnSend").click(function () {

            phoneNum = $.trim($("#txtPhone").val());
            if (phoneNum == "") {
                $.ligerDialog.warn("请输入手机号码");
                return;
            } else if (!validitor.phone(phoneNum)) {
                $.ligerDialog.warn("请输入正确的手机号码");
                return;
            } else {
                $.get("../Handlers/ExpertAccountHandler.ashx",
                {
                    func: "getvercode",
                    funccode: "expertpwdreset",
                    checkPhoneExists:true,
                    phone: phoneNum, 
                    stamp: new Date() - 0 
                }, function (rst) {
                    if (!rst.Success) {
                        $.ligerDialog.error(rst.Msg);
                    }
                }, "json");
                PhoneSendTimer($("#btnSend"), 60);
            }
        });

        /**
        *发送手机号码的计时器
        *obj 按钮
        *time 倒计时时限
        */
        function PhoneSendTimer(obj, time) {
            if (!obj) return;
            obj = $(obj);
            time = time || 60;
            var oriText = obj.val();

            obj.attr("disabled", "disabled").addClass("disabled");
            
            (function f() {
                if (time-- <= 0) {
                    obj.removeAttr("disabled").removeClass("disabled");
                    obj.val(oriText);
                    return;
                }
                setTimeout(function () {
                    obj.val(time + "秒后可重新发送");
                    f();
                }, 1000);
            } ())
        }

        //点击【确认】
        $("#btnToChangePwd").click(function () {
            phoneNum = $.trim($("#txtPhone").val());
            if (phoneNum == "") {
                $.ligerDialog.warn("请输入手机号码");
                return;
            } else if (!validitor.phone(phoneNum)) {
                $.ligerDialog.warn("请输入正确的手机号码");
                return;
            }
            verCode = $.trim($("#txtVerCode").val());
            if (!validitor.vercode(verCode)) {
                $.ligerDialog.warn("请输入正确的验证码");
                return;
            }
            $.get("../Handlers/ExpertAccountHandler.ashx",
                {
                    func: "checkvercode",
                    funccode: "expertpwdreset",
                    phone: phoneNum,
                    vercode: verCode,
                    stamp: new Date() - 0 
                }, function (rst) {
                    //// success:验证码正确 incorrent验证码错误 overcount超出当天规定次数
                    if(rst.result == "success") {
                            hashChange("#changePwdPage");
                    }else{
                        $.ligerDialog.warn(rst.msg);
                    }
                }
                , "json");
        });

        $("#btnChangePwd").click(function () {
            var p1 = $.trim($("#pwd").val());
            var p2 = $.trim($("#pwd2").val());

            if (!validitor.pwd(p1)) {
                $.ligerDialog.warn("密码需含字母和数字,至少六位");
                return false;
            }
            if (p1 != p2) {
                $.ligerDialog.warn("两次输入的密码不一致，请重新填写");
                return false;
            }
            $.post("../Handlers/ExpertAccountHandler.ashx", { func: "pwdreset", phone: phoneNum, pwd: p1 }, function (rst) {
                if (rst.success) {
                    $.ligerDialog.alert("密码修改成功,3秒后自动跳到登录页面");
                    setTimeout(function () {
                        window.location.href = "../LoginExpert.aspx";
                    }, 3000);
                } else {
                    $.ligerDialog.alert("密码修改失败");
                }
            }, "json");
        });
    </script>
</body>
</html>
